from openai import OpenAI
from globle import configs as cfg
import json

'''
需求：生成一个贪吃蛇游戏，并直接保存成html文件
'''



client = OpenAI(api_key=cfg.DEEPSEEK_API_KEY, base_url="https://api.deepseek.com")

completion = client.chat.completions.create(
    model="deepseek-chat",
    messages=[
        {
                "role": "user",
                "content": '''请帮我用 HTML 生成一个贪吃蛇游戏，所有代码都保存在一个 HTML 中。以json数据返回:
                            - html: 纯html的代码
                            - description: 说明内容
                           '''
        },
    ],
    response_format={"type":'json_object'},
)

json_str = completion.choices[0].message.content
dict = json.loads(json_str)
print(dict)
with open("greedy_snake.html", "w+") as f:
    f.write(dict['html'])